<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Aloha Editor command createLink tests</title>
	<!-- include qunit -->
	<link rel="stylesheet" href="../../vendor/qunit.css" type="text/css"/>

	<script type="text/javascript" src="../../vendor/qunit.js"></script>

	<script src="../../../lib/require.js" ></script>
	<!-- include jquery -->
	<script	src="../../../lib/vendor/jquery-1.7.2.js" ></script>
	<script type="text/javascript" src="../../vendor/jquery.simulate.js"></script>
	<script>
        require.config({
		    baseUrl: "../"
        });
		var Aloha = {
			settings: {
				jQuery: $,
				baseUrl: '../../../lib'
			}
		};
	</script>

	<!-- include aloha -->
	<script src="../../../lib/aloha.js" ></script>

	<!-- inject into testswarm -->
	<script type="text/javascript" src="../../vendor/swarminject.js"></script>
	<script>
		// load command test suite
		require( ['commandtest'] );
	</script>
	<style type="text/css">
		.aloha-editable ol li { list-style-type: decimal; margin: 1.5em; }
		.aloha-editable ol li ol li{ list-style-type: decimal; margin: 2em; }
	</style>
</head>
<body>
	<!-- include the tests -->
	<script>
	var tests = {
			defaultValue: '',
			defaultCommand: 'createlink',
			defaultAttributes: [ ],
			tests: [		        
          {  	start: "foo[]bar",
              value: "http://www.google.com",
              execResult: "foo[]bar"
          },
          {  	start: "<p>[foo</p><p>bar]</p>",
              value: "http://www.google.com/",
              execResult: "<p><a href=\"http://www.google.com/\">[foo</a></p><p><a href=\"http://www.google.com/\">bar]</a></p>"
          },
          {  	start: "<span>[foo</span> <span>bar]</span>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\"><span>[foo</span> <span>bar]</span></a>"
          },
          {  	start: "<p>[foo</p><p><span>bar</span></p><p>baz]</p>",
              value: "http://www.google.com/",
              execResult: "<p><a href=\"http://www.google.com/\">[foo</a></p><p><a href=\"http://www.google.com/\"><span>bar</span></a></p><p><a href=\"http://www.google.com/\">baz]</a></p>"
          },
          {   exclude: ["msie8.0", "msie7.0"],	
              start: "<p>[foo<p><br><p>bar]",
              value: "http://www.google.com/",
              execResult: "<p><a href=\"http://www.google.com/\">[foo</a></p><p><a href=\"http://www.google.com/\"><br></a></p><p><a href=\"http://www.google.com/\">bar]</a></p>"
          },
          {  	start: "<b>foo[]bar</b>",
              value: "http://www.google.com/",
              execResult: "<b>foo[]bar</b>"
          },
          {  	start: "<i>foo[]bar</i>",
              value: "http://www.google.com/",
              execResult: "<i>foo[]bar</i>"
          },
          {   exclude: ['webkit', 'msie7.0', 'msie8.0'],	
            	start: "<span>foo</span>{}<span>bar</span>",
              value: "http://www.google.com/",
              execResult: "<span>foo</span>{}<span>bar</span>"
          },
          {   include: ['webkit', 'msie7.0', 'msie8.0'],	
            	start: "<span>foo</span>{}<span>bar</span>",
              value: "http://www.google.com/",
              execResult: "<span>foo[]</span><span>bar</span>"
          },
          // Note: Following test also fails to run on IE9.
          {   exclude: ['webkit', 'msie'], 	
            	start: "<span>foo[</span><span>]bar</span>",
              value: "http://www.google.com/",
              execResult: "<span>foo[</span><span>]bar</span>"
          },
          {  	start: "foo[bar]baz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar]</a>baz"
          },
          {  	start: "foo[bar<b>baz]qoz</b>quz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar</a><b><a href=\"http://www.google.com/\">baz]</a>qoz</b>quz"
          },
          {  	start: "foo[bar<i>baz]qoz</i>quz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar</a><i><a href=\"http://www.google.com/\">baz]</a>qoz</i>quz"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
              start: "{<p><p><p>foo</p>}",
              value: "http://www.google.com/",
              execResult: "{<p></p><p></p><p><a href=\"http://www.google.com/\">foo</a></p>}"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
              start: "{<p><p><p>foo</p>}",
              value: "http://www.google.com/",
              execResult: "<p></p><p></p><p><a href=\"http://www.google.com/\">[foo]</a></p>"
          },
          // Note: Excluded table tests from IE 7/8 as it adds an extra space to result tds.
          {   exclude: ["msie8.0", "msie7.0"],	
              start: "<table><tbody><tr><td>foo<td>b[a]r<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody><tr><td>foo</td><td>b<a href=\"http://www.google.com/\">[a]</a>r</td><td>baz</td></tr></tbody></table>"
          },
          {   exclude: ["msie8.0", "msie7.0", "webkit"],	
            	start: "<table><tbody><tr data-start=1 data-end=2><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody><tr><td>foo</td>{<td><a href=\"http://www.google.com/\">bar</a></td>}<td>baz</td></tr></tbody></table>"
          },
          {   include: ["webkit"],	
            	start: "<table><tbody><tr data-start=1 data-end=2><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody><tr><td>foo</td><td><a href=\"http://www.google.com/\">[bar</a></td><td>}baz</td></tr></tbody></table>"
          },
          {   exclude: ["msie8.0", "msie7.0", "webkit"],	
            	start: "<table><tbody><tr data-start=0 data-end=2><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody><tr>{<td><a href=\"http://www.google.com/\">foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td>}<td>baz</td></tr></tbody></table>"
          },
          {   include: ["webkit"],	
            	start: "<table><tbody><tr data-start=0 data-end=2><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody><tr><td><a href=\"http://www.google.com/\">[foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td><td>}baz</td></tr></tbody></table>"
          },
          // Note: This fails on all IE versions
          {   exclude: ["msie", "webkit"],	
            	start: "<table><tbody data-start=0 data-end=1><tr><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody>{<tr><td><a href=\"http://www.google.com/\">foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td><td><a href=\"http://www.google.com/\">baz</a></td></tr>}</tbody></table>"
          },
          {   include: ["webkit"],	
            	start: "<table><tbody data-start=0 data-end=1><tr><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table><tbody><tr><td><a href=\"http://www.google.com/\">[foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td><td><a href=\"http://www.google.com/\">baz</a></td></tr></tbody></table>}"
          },
          {   exclude: ["msie8.0", "msie7.0", "webkit"],	
            	start: "<table data-start=0 data-end=1><tbody><tr><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "<table>{<tbody><tr><td><a href=\"http://www.google.com/\">foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td><td><a href=\"http://www.google.com/\">baz</a></td></tr></tbody>}</table>"
          },
          {   include: ["webkit"],	
            	start: "<table data-start=0 data-end=1><tbody><tr><td>foo<td>bar<td>baz</table>",
              value: "http://www.google.com/",
              execResult: "{<table><tbody><tr><td><a href=\"http://www.google.com/\">foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td><td><a href=\"http://www.google.com/\">baz</a></td></tr></tbody></table>}"
          },
          {   exclude: ["msie8.0", "msie7.0"],	
            	start: "{<table><tr><td>foo<td>bar<td>baz</table>}",
              value: "http://www.google.com/",
              execResult: "{<table><tbody><tr><td><a href=\"http://www.google.com/\">foo</a></td><td><a href=\"http://www.google.com/\">bar</a></td><td><a href=\"http://www.google.com/\">baz</a></td></tr></tbody></table>}"
          },
          {  	start: "<a href='http://www.google.com/'>foo[bar]baz</a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">foo[bar]baz</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
              start: "<a href='http://www.google.com/'>foo[barbaz</a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">foo[barbaz</a>}"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "<a href='http://www.google.com/'>foo[barbaz</a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">foo[barbaz]</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='http://www.google.com/'>foobar]baz</a>",
              value: "http://www.google.com/",
              execResult: "{<a href=\"http://www.google.com/\">foobar]baz</a>"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='http://www.google.com/'>foobar]baz</a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobar]baz</a>"
          },
          {   exclude: ["webkit","msie8.0", "msie7.0"],	
              start: "{<a href='http://www.google.com/'>foobarbaz</a>}",
              value: "http://www.google.com/",
              execResult: "{<a href=\"http://www.google.com/\">foobarbaz}</a>"
          },
          {   include: ["webkit","msie8.0", "msie7.0"],	
            	start: "{<a href='http://www.google.com/'>foobarbaz</a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobarbaz]</a>"
          },
          {  	start: "<a href='http://www.google.com/'>[foobarbaz]</a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobarbaz]</a>"
          },
          {  	start: "foo<a href='http://www.google.com/'>[bar]</a>baz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar]</a>baz"
          },
          {  	start: "[foo]<a href='http://www.google.com/'>bar</a>baz",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foo]bar</a>baz"
          },
          {  	start: "foo<a href='http://www.google.com/'>bar</a>[baz]",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">bar[baz]</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
              start: "foo[<a href='http://www.google.com/'>bar</a>]baz",
              value: "http://www.google.com/",
              execResult: "foo[<a href=\"http://www.google.com/\">bar</a>]baz"
          },
          {   include: ["webkit"],	
              start: "foo[<a href='http://www.google.com/'>bar</a>]baz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar]</a>baz"
          },
          {   include: ["msie8.0", "msie7.0"],	
              start: "foo[<a href='http://www.google.com/'>bar</a>]baz",
              value: "http://www.google.com/",
              execResult: "foo{<a href=\"http://www.google.com/\">bar]</a>baz"
          },
          {  	start: "foo<a href='http://www.google.com/'>[bar</a>baz]",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[barbaz]</a>"
          },
          {  	start: "[foo<a href='http://www.google.com/'>bar]</a>baz",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobar]</a>baz"
          },
          {  	start: "[foo<a href='http://www.google.com/'>bar</a>baz]",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobarbaz]</a>"
          },
          {  	start: "<a href='otherurl'>foo[bar]baz</a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">foo[bar]baz</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
              start: "<a href='otherurl'>foo[barbaz</a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">foo[barbaz</a>}"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "<a href='otherurl'>foo[barbaz</a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">foo[barbaz]</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'>foobar]baz</a>",
              value: "http://www.google.com/",
              execResult: "{<a href=\"http://www.google.com/\">foobar]baz</a>"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'>foobar]baz</a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobar]baz</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'>foobar]baz</a>",
              value: "http://www.google.com/",
              execResult: "{<a href=\"http://www.google.com/\">foobar]baz</a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'>foobarbaz</a>}",
              value: "http://www.google.com/",
              execResult: "{<a href=\"http://www.google.com/\">foobarbaz}</a>"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'>foobarbaz</a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobarbaz]</a>"
          },
          {  	start: "<a href='otherurl'>[foobarbaz]</a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobarbaz]</a>"
          },
          {  	start: "foo<a href='otherurl'>[bar]</a>baz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar]</a>baz"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
              start: "foo[<a href='otherurl'>bar</a>]baz",
              value: "http://www.google.com/",
              execResult: "foo[<a href=\"http://www.google.com/\">bar</a>]baz"
          },
          {   include: ["webkit"],	
            	start: "foo[<a href='otherurl'>bar</a>]baz",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[bar]</a>baz"
          },
          {   include: ["msie8.0", "msie7.0"],	
            	start: "foo[<a href='otherurl'>bar</a>]baz",
              value: "http://www.google.com/",
              execResult: "foo{<a href=\"http://www.google.com/\">bar]</a>baz"
          },
          {  	start: "foo<a href='otherurl'>[bar</a>baz]",
              value: "http://www.google.com/",
              execResult: "foo<a href=\"http://www.google.com/\">[barbaz]</a>"
          },
          {  	start: "[foo<a href='otherurl'>bar]</a>baz",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobar]</a>baz"
          },
          {  	start: "[foo<a href='otherurl'>bar</a>baz]",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\">[foobarbaz]</a>"
          },
          {  	start: "<a href='otherurl'><b>foo[bar]baz</b></a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\"><b>foo[bar]baz</b></a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
              start: "<a href='otherurl'><b>foo[barbaz</b></a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\"><b>foo[barbaz</b></a>}"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "<a href='otherurl'><b>foo[barbaz</b></a>}",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\"><b>foo[barbaz]</b></a>"
          },
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'><b>foobar]baz</b></a>",
              value: "http://www.google.com/",
              execResult: "{<a href=\"http://www.google.com/\"><b>foobar]baz</b></a>"
          },
          {   include: ["webkit", "msie8.0", "msie7.0"],	
            	start: "{<a href='otherurl'><b>foobar]baz</b></a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\"><b>[foobar]baz</b></a>"
          },
          {  	start: "<a href='otherurl'><b>[foobarbaz]</b></a>",
              value: "http://www.google.com/",
              execResult: "<a href=\"http://www.google.com/\"><b>[foobarbaz]</b></a>"
          },
          {   exclude: ['msie7.0'],	
              start: "<a name='abc'>foo[bar]baz</a>",
              value: "http://www.google.com/",
              execResult: "<span name=\"abc\">foo<a href=\"http://www.google.com/\">[bar]</a>baz</span>"
          },
          {   exclude: ['msie7.0'],	
              start: "<a name='abc'><b>foo[bar]baz</b></a>",
              value: "http://www.google.com/",
              execResult: "<span name=\"abc\"><b>foo<a href=\"http://www.google.com/\">[bar]</a>baz</b></span>"
          },
          {  	start: "foo[bar]baz",
              value: "",
              execResult: "foo[bar]baz"
          }
			]
	}
	</script>
	<h1 id="qunit-header">Aloha Editor command createlink tests</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>
	<div id="qunit-fixture"></div>
	<div id="edit" style="margin:20px; border:1px solid #000000;"></div>
	<div id="logBody"></div>
	</div>
</body>
</html>
